package com.yanqu.road.server.cmd.activity.peakseacraft;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.pb.union.UnionActivityGroupProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.chuhan.CrossChuHanMgr;
import com.yanqu.road.server.manager.activity.chuhan.activity.CrossChuHanActivity;
import com.yanqu.road.server.manager.activity.fivehero.CrossFiveHeroActivity;
import com.yanqu.road.server.manager.activity.fivehero.CrossFiveHeroMgr;
import com.yanqu.road.server.manager.activity.peakseacraft.PeakSeacraftActivity;
import com.yanqu.road.server.manager.activity.peakseacraft.PeakSeacraftMgr;
import com.yanqu.road.server.manager.activity.tonbing.CrossTonBingMgr;
import com.yanqu.road.server.manager.activity.tonbing.activity.CrossTonBingActivity;
import com.yanqu.road.server.manager.peakstronghold.CrossPeakStrongholdMgr;
import com.yanqu.road.server.manager.peakstronghold.PeakStrongholdActivityModel;
import com.yanqu.road.server.protocol.CrossProtocol;

@Cmd(code = CrossProtocol.C_PEAK_LOCK_REGISTRATION_PROMOTION_UNION, desc = "巅峰锁定报名期排行返回")
public class CrossPeakLockPromotionUnionCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        UnionActivityGroupProto.BaseUnionActivityGroupMsg baseUnionActivityGroupMsg = UnionActivityGroupProto.BaseUnionActivityGroupMsg.parseFrom(packet.getBytes());

        RankProto.CrossUnionRankListLockMsg lockMsg = RankProto.CrossUnionRankListLockMsg.parseFrom(baseUnionActivityGroupMsg.getMsg().toByteArray());
        int activityId = lockMsg.getActivityId();
        ActivityInfo activityInfo = ActivityMgr.getActivityInfoMayLoadDB(activityId);
        if (null == activityInfo) {
            log.error("收到报名期截止名单,，但是活动{}不存在",
                    activityId);
            return;
        }

        if (activityInfo.getType() == eActivityType.PeakSeacraftActivity.getValue()) {
            PeakSeacraftActivity southSeaActivity = PeakSeacraftMgr.getPeakSeacraftActivity(activityId, lockMsg.getGroupId());
            if (southSeaActivity != null) {
                southSeaActivity.lockRegistrationPromotionUnion(lockMsg);
            }
        } else if (activityInfo.getType() == eActivityType.TonBingActivity.getValue()) {
            CrossTonBingActivity ac = CrossTonBingMgr.getActivity(activityId);
            if (ac != null) {
                CrossTonBingMgr.getLogger().error("巅峰统兵收到本服发来的锁定榜单");
                ac.lockUnion(lockMsg);
            }
        } else if (activityInfo.getType() == eActivityType.ChuHanZB.getValue()) {
            CrossChuHanActivity activity = CrossChuHanMgr.getActivity(activityId, lockMsg.getGroupId());
            if (activity != null) {
                CrossChuHanMgr.getLogger().error("楚汉争霸收到游戏服发来的锁定榜单");
                activity.lockUnion(lockMsg);
            }
        } else if (activityInfo.getType() == eActivityType.FiveHero.getValue()) {
            CrossFiveHeroActivity ac = CrossFiveHeroMgr.getFiveHeroActivity(activityId, lockMsg.getGroupId());
            if (ac != null) {
                ac.lockUnion(lockMsg);
            }
        } else if (activityInfo.getType() == eActivityType.PeakStrongHold.getValue()) {
            PeakStrongholdActivityModel activityModel = CrossPeakStrongholdMgr.getActivityModel(activityId, lockMsg.getGroupId());
            if (activityModel != null) {
                activityModel.lockRegistrationPromotionUnion(lockMsg);
            }
        } else {
            log.error("收到报名期截止名单,，但是活动{}不存在,type={}", activityId, activityInfo.getType());
        }
    }

    @Override
    public void sendData() {

    }
}
